Debugging with keystroke using async actor?
# apify-platform
a
message has been deleted
r
Hello - im am testing with the basic template for python: https://apify.com/templates/python-start For debugging reasons i would like to output every heading and then waiting for a keystrike using using the following code code below. But when i press a key when running the program in the terminal i does not go to the next element. How can i do this using async so i get every output after a keystroke? Code: from __future__ import annotations from apify import Actor from bs4 import BeautifulSoup from httpx import AsyncClient async def main() -> None: async with Actor: actor_input = await Actor.get_input() or {'url': 'https://apify.com/'} url = actor_input.get('url') if not url: raise ValueError('Missing "url" attribute in input!') async with AsyncClient() as client: Actor.log.info(f'Sending a request to {url}') response = await client.get(url, follow_redirects=True) soup = BeautifulSoup(response.content, 'lxml') headings = [] for heading in soup.find_all(['h1', 'h2', 'h3', 'h4', 'h5', 'h6']): heading_object = {'level': heading.name, 'text': heading.text} Actor.log.info(f'Extracted heading: {heading_object}') input("Press!") headings.append(heading_object) await Actor.push_data(headings)
a
@rapidtech1898_10568 just advanced to level 1! Thanks for your contributions! 🎉
o
Yes, input() in async doesn't work as it should — it blocks everything. To wait for Enter to be pressed, simply wrap input() in await asyncio.to_thread(...), and it will work as it should. Like this: await asyncio.to_thread(input, "Press Enter...").
r
Hello - thanks for the response - I tried it this way: async def main() -> None: async with Actor: await Actor.set_status_message('Starting actor...') asyncio.to_thread(input, "Press Enter...") But its not stopping in any way with that.
o
please repost Your question to #1170038966817398894 Maybe there You will get some help.